//
//  XGTabBar.m
//  BSBuDeJie
//
//  Created by monkey on 2018/12/10.
//  Copyright © 2018 itcast. All rights reserved.
//

#import "XGTabBar.h"

@interface XGTabBar()

/// 发布按钮
@property (nonatomic,strong) UIButton *composeButton;

@end

@implementation XGTabBar


#pragma mark - 构造方法

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setUpUI];
    }
    
    return self;
}

- (void)setUpUI
{
    [self addSubview:self.composeButton];
}

#pragma mark - 其他方法

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    // 将tabBar分成五等分 中间预留出一个位置
    CGFloat width = self.width / 5.f;
    CGFloat height = self.height;
    int i = 0;
    for (UIView *view in self.subviews) {
        if ([view isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            i = (i == 2 ? i + 1 : i);
            view.frame = CGRectMake(i * width, 0, width, height);
            i++;
        }
    }
    
    // 布局发布按钮
    self.composeButton.center = CGPointMake(self.width / 2, self.height / 2);
}

#pragma mark - 懒加载

- (UIButton *)composeButton
{
    if (_composeButton == nil) {
        _composeButton = [UIButton buttonWithImageName:@"tabBar_publish_icon" highlightedImageName:@"tabBar_publish_click_icon" target:nil action:nil];
    }
    
    return _composeButton;
}

@end
